package com.stylefeng.guns.modular.vpn_connection_manage.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.vpn_connection_manage.service.IConnectionService;

/**
 * 用户在线管理控制器
 * @Date 2020-03-26 12:28:12
 */
@Controller
@RequestMapping("/connection")
public class ConnectionController extends BaseController {

    private String PREFIX = "/vpn_connection_manage/connection/";

    @Autowired
    private IConnectionService connectionService;

    /**
     * 跳转到用户在线管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "connection.html";
    }

    /**
     * 获取用户在线管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(value = "userName",required = false) String userName,
                       @RequestParam(value = "page",defaultValue = "0") Integer page,
                       @RequestParam(value = "limit",defaultValue = "20") Integer size,
                       @RequestParam(value = "serverType",required = false) Integer serverType) {
        return connectionService.findConnections(userName,page,size,serverType);
    }

    /**
     * 强制下线
     * @param connectId
     * @return
     */
    @RequestMapping(value = "/offLine")
    @ResponseBody
    public Object offLine(@RequestParam(value = "id") Integer connectId) {
        return connectionService.offLine(connectId);
    }

}
